//
//  ZTAdViewController.m
//  项目练习
//
//  Created by 张江涛 on 15/11/29.
//  Copyright © 2015年 张江涛. All rights reserved.
//

#import "ZTAdViewController.h"
#import "ZTTabBarController.h"

@interface ZTAdViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *bgImage;
@property (weak, nonatomic) IBOutlet UIImageView *adImageView;

/** 定时器*/
@property(weak,nonatomic) NSTimer *times;
//跳过的按钮
@property (weak, nonatomic) IBOutlet UIButton *skipBtn;
/** 广告剩余的时间*/
@property(assign,nonatomic) int  adLeftTime;

@end

@implementation ZTAdViewController
//广告停留时间
 static int const Adtime = 0;

- (void)viewDidLoad {
    [super viewDidLoad];
    CGFloat screenH = [UIScreen mainScreen].bounds.size.height;
    if (screenH ==736 ) {
        self.bgImage.image = [UIImage imageNamed:@"LaunchImage-800-Portrait-736h@3x"];
    }
    else if (screenH == 667)
    {
        self.bgImage.image = [UIImage imageNamed:@"LaunchImage-800-667h"];
    }
    else if (screenH == 568)
    {
        self.bgImage.image = [UIImage imageNamed:@"LaunchImage-568h"];
    }
    else{
        self.bgImage.image = [UIImage imageNamed:@"LaunchImage"];
    }
    
    BOOL hidAd = NO;
    if (hidAd) {
        //显示提供的广告
    }
    else
    {
        self.adImageView.image = [UIImage imageNamed:@"Ad.jpg"];
    }
    //交互
    self.adImageView.userInteractionEnabled = YES;
    //添加手势
    UITapGestureRecognizer *top = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(adClick)];
    [self.adImageView addGestureRecognizer:top];
    
    //广告剩余时
    self.adLeftTime = Adtime;
    
       //定时器
    NSTimer * timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTime) userInfo:nil repeats:YES];
    [[NSRunLoop mainRunLoop]addTimer:timer forMode:NSRunLoopCommonModes];
    self.times = timer;
    
}

//跳过按钮
- (IBAction)ski {
    
    //关闭定时器
    [self.times invalidate];
    //改变根控制器
    [UIApplication sharedApplication].keyWindow.rootViewController = [[ZTTabBarController alloc]init];
    
}

//广告点击
- (void)adClick
{
    ZTLongFunc;
  
//        //改变根控制器
//    [UIApplication sharedApplication].keyWindow.rootViewController = [[UIViewController alloc]init];
}


//更新时间
- (void)updateTime
{
    self.adLeftTime--;
    //设置按钮上的文字
    NSString *str = [NSString stringWithFormat:@"跳过(%zd)",self.adLeftTime];
    [self.skipBtn setTitle:str forState:UIControlStateNormal];
    
    if (self.adLeftTime == -1) {
        [self ski];
    }
    
}


@end
